<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 字面量
        let obj = {
            name:"张三",
            age : "10",
            speak: function () {
                console.log("可以说话");
            },
            eat(){
                console.log("可以说话");
            }
        }
        // 构造函数，缺陷 非常容易 造成函数的调用
        let Person = function (name,age) {
            this.name = name,
            this.age = age,
            this. speak = function () {
                console.log("可以说话");
            }
        }
        // 挂到原型上 Person.prototype 原型对象
        Person.prototype.eat = function () {
            console.log("吃骨头");
        }
        let a = new Person('李四','10')
        console.log(a);

        // 要求必须在new 情况下才可以使用
        class Dag{
            // 构造方法
            constructor(name,age) {
                this.name = name,
                this.age = age
            }
            // 方法
            speak = function () {
                console.log("汪汪叫");
            }

            eat(){
                console.log("吃骨头");
            }
        }
        let dd = new Dag("旺财",3)
        // let c = Dag("旺财",3)
        // console.log(c);
        console.log(typeof Dag);
        console.log(dd);
    </script>
</body>
</html>